﻿using System;
using System.Linq;
using System.Linq.Expressions;
using OS.Infrastructure.Domain;

namespace TaskKernel.Domain.Nhibernate.NHibernateLayer
{
    internal class SelectDepartmentsWhereIamExecutor : Specification<Department>
    {
        private readonly Account _account;

        public SelectDepartmentsWhereIamExecutor(Account account)
        {
            _account = account;
        }

        public override Expression<Func<Department, bool>> IsSatisfiedBy()
        {
            return x => x.UsersWithRole.Any(p => p.User.UID == _account.UID && p.Role == RoleEnum.Executor);
        }
    }

    internal class SelectDepartmentsWhereIamAdmin : Specification<Department>
    {
        private readonly Account _account;

        public SelectDepartmentsWhereIamAdmin(Account account)
        {
            _account = account;
        }

        public override Expression<Func<Department, bool>> IsSatisfiedBy()
        {
            return x => x.UsersWithRole.Any(p => p.User.UID == _account.UID && (p.Role == RoleEnum.Admin));
        }
    }
}